using System;
using UnityEngine;
using DG.Tweening;
using System.Collections.Generic;
using UI;
using Unity.Mathematics;
using Unity.VisualScripting;
using UnityEngine.EventSystems;
using UnityEngine.UI;
using Utilities;
using EventHandler = Utilities.EventHandler;

public class Card : MonoBehaviour, IPointerClickHandler
{


    [SerializeField] public MiniPeopleEventType type;
    [SerializeField] private float cost;
    public bool canSelect;  //能否被选中
    public DragCard dragCard;
    public int cardIndex;
    public GameObject cardSlotPrefab;
    public List<Sprite> cardSprites;
    public GameObject emptyCard;

    public void Start()
    {
        
        dragCard = GetComponent<DragCard>();
    }

    public void OnPointerClick(PointerEventData eventData)
    { //点击卡片
        if (canSelect)
        {
            dragCard.dragging = true;
        }
    }

    public void ActivateCardEffect()
    { //卡片效果激活
        Debug.Log("卡片效果被激活");
        
        EventHandler.CallOnWeatherActivate(type);
        EventHandler.CallClearingCardsSlot(cardIndex);
    }
        /// <summary>
        /// 卡片升级
        /// </summary>
        /// <returns></returns>
    public bool LevelUp()
    {
        if ((int)type % 3 == 2)
        {
            return false;
        }
        type = (MiniPeopleEventType)((int)type + 1);
        GetComponent<Image>().sprite = cardSprites[(int)type%3]; //替换卡牌Image
        if((int)type%3==2)
        {
            GetComponent<Image>().DOColor(Color.yellow, 1f);//卡牌三级时换色
        }
        return true;
    }

    public void StartPreview()
    { //开始预览-可以被选中
        canSelect = true;
    }

    public void StopPreview()
    {  //关闭预览-不可被选中
        canSelect = false;
    }
}